Repository navigation
fix(studio): caption editing works in a sealed preview - #8002
Conversation
terencecho
left a comment
There was a problem hiding this comment.
Reviewed pinned head c37aea2. No correctness, security, or data-loss blocker found. The new caption requests use the existing editing-port boundary with validated parameters; the same-origin paths remain direct. Sealed detection, overlay measurements, queued transforms, drag completion, property-panel transforms, sequential nudges, and undo were reviewed.
Validation: full workspace build passed; 162 targeted core runtime/protocol tests and 111 caption/Studio tests passed (273 total). Restoring the base detection hook makes CaptionOverlay.sealed.test.ts fail with zero boxes instead of two, confirming the required regression. Restored the reviewed source afterward and verified a clean tracked diff.
Current CI has 85 successes, 11 skips, 1 cancellation and 2 failures. The failed Windows engine-cli-2 log identifies urlDownloader.runtimes.test.ts, the Bun private-address test timing out at 5000 ms; the other failure is the Windows aggregate. That file is outside this patch. I did not rerun Windows or exercise a real browser/save-to-disk flow; the sealed integration is a happy-dom test with the real runtime agent. The documented 2048 combined group/word detection bound remains a limitation.
— tai (automated review)
…g port in a sealed preview
2e92cba to
0fd6d09
Compare
vanceingalls
left a comment
There was a problem hiding this comment.
Approved at 0fd6d09.
- Params:
captionWordsParamsandcaptionTransformParamsare registered inPARAM_PARSERS, so they're checked before any handler runs. Indices are safe integers under 100,000, entries are capped atMAX_DESCRIBE_HANDLES,setkeys are whitelisted and extra keys are refused. - Port: no new listener or handshake change. The frame returns only rects and transforms, which
describealready exposes. - Writes: no text or timings come back from the frame, and persisted writes go only to
caption-overrides.json. - Studio side: frame data is shape-checked (
readFrameWord,readFrameWordBoxes,isPlainRecord). - Rebase: the diff is 12 files, all caption or editing-port scope, and the size-budget file isn't touched.
- Test: the
fails without the fix:line is present.
Should-fix:
- Stale detection: the sealed branch of
useCaptionDetection.ts(loadCaptions, ~L160) makes several round trips, checks onlyisEditMode, and isn't cancelled by the effect cleanup. Switch composition mid-detection and A's chain can callsetModel/setEditMode(true)after B's reset. Add an epoch like #7999'sreads.current. - Writes after unmount: in
CaptionOverlay.tsx, thenudgingchain and the pointer-upsealed.last.then(storeStyle)ignoredisposed, so they can store a stale style after unmount. - Unbounded reply values:
readFrameWordonly checks that values are finite. One huge frame-reported value gets persisted, thencaptionTransformParamsrejects every later write and undo for that word. Apply the same 100,000 bound to replies.
…o moves on A caption detection, nudge or drag still waiting on a sealed preview no longer writes after its effect is gone, and a frame-reported word transform past the frame's own write bound is refused instead of stored. Each has a test against the real editing agent that holds the frame's answer open.
|
Thanks. All three are fixed in 1a9df6c, each with a test in
|
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at 1a9df6c. This covers my three should-fixes.
- Detection:
useCaptionDetectiontakes adisposedflag that the cleanup sets, so a detection still in flight can't apply the old composition's model or enter edit mode. - Late replies:
CaptionOverlaychecksdisposedin the nudge chain andliveRefon the pointer-upsealed.last, so a late reply stores nothing. - Bounds:
readFrameWordapplies the sharedMAX_CAPTION_TRANSFORM(100,000) to x, y, scale and rotation, so an out-of-range reply can't be stored and block later writes.
Tests cover all three.
…me word helpers Keeps the caption overlay under the studio file size limit and its comment share at the base. No behaviour change.
|
Thanks for the re-approval. The new head, 6194768, only moves code to pass the size and comment checks. The sealed nudge queue moved from |
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at 6194768. This is a refactor only: the sealed nudge queue moved to sealedNudger in CaptionOverlayUtils.ts. The same live() check runs before each nudge starts and before it stores, and nudges stay serialized.
vanceingalls
left a comment
There was a problem hiding this comment.
Re-approved at d1f049e. The only change is a one-line refactor in CaptionOverlayUtils.ts, keeping the nudge request inside its helper file. Behaviour is unchanged.
What
Caption editing works when Studio's preview runs sealed (an opaque-origin frame). Before this, a sealed preview never entered caption edit mode, so the caption overlay and its property panel never showed.
With a same-origin preview nothing changes: every caller keeps its direct path, and the editing port is used only when
previewFrameOpaque(iframe)is true (the same split asuseElementPicker).How
Two new editing-port request kinds, each handled in its own file under
packages/core/src/runtime/editing/:caption-words: Studio sends how many words its model has per.caption-group. The frame returns the boxes of words in visible groups. A group written as plain text is split into word spans inside the frame, as Studio's same-origin path does today.caption-transform: reads, or withsetwrites, a word's wrapper transform (x, y, scale, rotation). It uses the page'sgsap.setwhen the page has GSAP, else a CSS transform, asCaptionOverlayUtilsdoes. It returns the transform after the write and the word's box.Params are validated like the existing kinds: indices are bounded integers, transform values are finite and within
MAX_DRAFT_PX, at mostMAX_DESCRIBE_HANDLESentries per request, and unknown keys are refused.Studio side:
caption-transform.applyCaptionModelToIframe) writes each word's restored transform through the same queue.query,describe,ancestorsandcomputed-styleskinds read the caption groups, words, composition hosts and root size. The groups and words are rebuilt, in document order and nesting, in a detached document, and their first word's and group's computed styles are served by a stand-ingetComputedStyle.parseCaptionCompositionthen runs unchanged. Detection keeps copies of the parser's two selectors, since the parser does not export them.Kept direct reads (they work on an opaque frame): the two
e.source !== iframe.contentWindowchecks inCaptionOverlay.tsxanduseCaptionDetection.tscompare window identity, which is allowed across origins. The direct same-origin branches stay as they were.Behavior differences, sealed only:
getWordEl's counting).Package size: the inspector inlines the runtime script, so the two new kinds grow its unpacked size; it stays within the current budget in
scripts/package-size-budgets.json(the size check passes), so this PR does not change the budget.Bound: sealed detection reads at most 2048 caption groups and words together (one
querypage). A larger caption composition does not enter edit mode while sealed.Before
A sealed preview of a caption composition: Studio never enters caption edit mode.
After
The same preview enters caption edit mode, and a clicked word shows its selection box and handles. (A "Caption changes couldn't be saved" notice from this local setup was closed before the shot; it shows the same way with a same-origin preview.)
Tests
fails without the fix:
packages/studio/src/captions/components/CaptionOverlay.sealed.test.ts("caption overlay shows + edits sealed") fails onmainwithAssertionError: expected [] to have a length of 2 but got +0, because the sealed preview never enters caption edit mode.CaptionOverlay.sealed.test.ts("caption overlay shows + edits sealed", the first commit): runs the real runtime editing agent behind a frame Studio cannot read. It covers detection, boxes, a drag that moves before the press read returns, a panel X edit, an arrow-key nudge and undo. Onmainit fails because the sealed preview never enters edit mode (no boxes).editing/captionWords.test.ts: the in-frame split, visibility, CSS and GSAP writes, and missing words.editingAgent.test.ts: new invalid-params cases for both kinds;hellolists them.